package com.twu.biblioteca;
import java.util.Scanner;
import java.util .ArrayList;

/**
 * Created with IntelliJ IDEA.
 * User: Demon
 * Date: 13-6-27
 * Time: 上午10:44
 * To change this template use File | Settings | File Templates.
 */
public class MenuOption {

    //private UserLogin user;
    private static int bookListChoice=1;    //other,membership,manager can choose the book_list_choice
    private static int movieListChoice=2;   //membership,manager can choose the membership_choice
    private static int reserveBookChoice=3;    //manager can choose the management_choice
    private static int membershipChoice=4;
    private ArrayList<User> userList=new ArrayList<User>();
    private int userIndex=0;
    private int userChoice;
    //private BookList book_list;
    private ArrayList<BookList> bookList=new ArrayList<BookList>();
    private ArrayList<MovieList> movieList=new ArrayList<MovieList>();
    private Helper help=new Helper();

    MenuOption(ArrayList<User> list,int index){
        userList=list;
        userIndex=index;

        BookList one=new BookList();
        one.setBookName("math");
        bookList.add(one);
        BookList two=new BookList();
        two.setBookName("English");
        bookList.add(two);
        BookList three=new BookList();
        three.setBookName("PE");
        bookList.add(three);
        BookList four=new BookList();
        four.setBookName("chemistry");
        bookList.add(four);
        BookList five=new BookList();
        five.setBookName("physics");
        bookList.add(five);
        BookList six=new BookList();
        six.setBookName("biology");
        bookList.add(six);

        MovieList movie1=new MovieList("Spring1","2002","Tom","6");
        movieList.add(movie1);
        MovieList movie2=new MovieList("Spring2","2002","Tom","5");
        movieList.add(movie2);
        MovieList movie3=new MovieList("Spring3","2002","Tom","4");
        movieList.add(movie3);
        MovieList movie4=new MovieList("Spring4","2002","Tom","3");
        movieList.add(movie4);
        MovieList movie5=new MovieList("Spring5","2002","Tom","2");
        movieList.add(movie5);
        MovieList movie6=new MovieList("Spring6","2002","Tom","1");
        movieList.add(movie6);
        MovieList movie7=new MovieList("Spring7","2002","Tom","N/A");
        movieList.add(movie7);
        MovieList movie8=new MovieList("Spring8","2002","Tom","8");
        movieList.add(movie8);
        MovieList movie9=new MovieList("Spring9","2002","Tom","9");
        movieList.add(movie9);
        MovieList movie10=new MovieList("Spring10","2002","Tom","5");
        movieList.add(movie10);
        MovieList movie11=new MovieList("Spring11","2002","Tom","N/A");
        movieList.add(movie11);
        MovieList movie12=new MovieList("Spring12","2002","Tom","7");
        movieList.add(movie12);
        MovieList movie13=new MovieList("Spring13","2002","Tom","N/A");
        movieList.add(movie13);
        MovieList movie14=new MovieList("Spring14","2002","Tom","N/A");
        movieList.add(movie14);
        MovieList movie15=new MovieList("Spring15","2002","Tom","10");
        movieList.add(movie15);
    }

    public void Option( ){
        System.out.println("Please input menu option(1 for book list,2 for movie option,3 for reserve book, 4 for membership):");
        help.helpInput();
        userChoice=Integer.parseInt(help.getWhatInput());
        JudgeUserChoice( );
    }

    public void   JudgeUserChoice( ) {
        if(userChoice<3){
            System.out.println("The option you have chosen is not open, please talk to a Librarian. Thank you.");
        }
        if(userChoice==3){
            System.out.println("You have chosen the reserve book option! ");
            ShowBookList();
            reserveBook();
        }
        if(userChoice==4) {
            System.out.println("You have chosen the membership option!");
            CheckMemberShipDetails();
        }
    }

    public void ShowBookList() {
        for(BookList book:bookList){
            System.out.println(book.getBookName());
        }
    }

    public void reserveBook(){
        String bookName=new String();
        boolean mark=false;
        System.out.println("Please input the book name you want to reserve:");
        help.helpInput();
        bookName=help.getWhatInput();
        for(BookList book:bookList)  {
            mark=book.CheckReserveBookIsLegal(bookName);
            if(mark==true){
                System.out.println("you have reserve the book!");
            }
        }
        if(mark==false){
            System.out.println("Sorry we don't have that book yet");
        }
    }

    public void CheckMemberShipDetails(){
        User temp=new User();
        if(userChoice==4){
            temp=userList.get(userIndex);
            System.out.println("you are the membership, your message are as follows:");
            System.out.println("name:" + temp.getUserName());
            System.out.println("email address:" + temp.getUserEmailAddress());
            System.out.println("phone number:" + temp.getUserPhoneNumber());
            //System.out.println("Please talk to a Librarian. Thank you.");
        }
    }
}
